<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>PH1出货扫描</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">	
    <link rel="stylesheet" href="./4/lumen/bootstrap.css" media="screen">
    <link rel="stylesheet" href="./_assets/css/custom.min.css">
  </head>
  <body >
  <div class="container"; style="position:relative; left:0px; top:0px; overflow:auto"; >
	<form id="myform">
	
	  <fieldset>
		<legend>PH1出货扫描</legend>
		
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">發貨單號:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="FA180529009" id="Order_id" type="text">
		  </div>
		</div>	
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">铝箔袋:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="S   M   H   AF185190D30008524011" id="lv_shipment" type="text">
		  </div>
		  <div class="col-sm-2">
			<input readonly="" class="form-control-plaintext" id="msg" value="" type="text">
		  </div>
		</div>	
		
		<div class="form-group row">
		  
		  <div class="col-sm-12">
		  <br>
		  </div>
		</div>

		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">Lot_ID:</label>
		  <div class="col-sm-8">
		  <input class="form-control" placeholder="170808C001" id="Lot_ID" type="text">
		  </div>
		  <div class="col-sm-2">
			<input readonly="" class="form-control-plaintext" id="msg1" value="" type="text">
		  </div>
		</div>	
		
		<div class="form-group row">
		  <div class="col-sm-4">
			
		  </div>
		  <div class="col-sm-4">
			<button type="button" id="btnNextbox" class="btn btn-primary">下一箱</button>
		  
		  </div>
		</div>	
		<div class="form-group row" id="my"></div>
		
		 <div class="row">
			<div class="col-md-12">
				<table class="table table-hover" id="dats_table">
					<thead>
						<tr>
							<th id="numberss">包数</th>
							<th>工单号</th>
							<th>lotID</th>
							<th>productid</th>
							<th>型号</th>
							<th>number</th>
							<th>catcode</th>
							<th id="sumqty">qty</th>
						</tr>
				 	</thead>
				 	<tbody>
						
				 	</tbody>
				</table>
			</div>
		</div> 
	</form>	
	
	</div>
    <script src="./_vendor/jquery/dist/jquery.min.js"></script>
    <script src="./_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="./_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./_assets/js/custom.js"></script>
	<script src="./jexcel-master/dist/js/jquery.jexcel.js"></script>
	<script src="./layui/layui.js"></script>
	<script>
	var disks;
	var qty=0;
	var disksnumber=0;//记录铝箔袋被扫的次数及用于动态ID的递增
	var Order;
	
	var a = new Array();
	var b = new Array();
	var  disksnumber=0;
	var sumqty=0;
	var testlotID=0;
	layui.use(['layer','form','element'], function(){
		//layer.msg('初始化正常!');
		//如果HTML5WEB存储存在,就查询,否则就弹窗提示
		if (localStorage.name){
			//$("#YGXM").val(localStorage.name)
			for(var i=0;i<localStorage.name;i++){
				console.log(localStorage.name[i]);
			}
			console.log(localStorage.name);
			//console.log("员工信息: "+ localStorage.name);
		}
	});
		$("#Order_id").keypress(function(e){    //通過訂單號獲取bincode信息
		 
		  var key = e.which;
		  if (key == 13) {
		   a.splice(0,a.length);
			$("#msg").val("");
			$("#msg1").val("");
			Order=$("#Order_id").val();
			console.log(Order);
				$.ajax({
					type:'POST',
					url: "ph1order.php",//POST傳一個超長字串到後端
					data:"Order="+Order,
					dataType : "JSON",
					success: function(sss){
						for(var i=0;i<sss.length;i++){
							b[i]=sss[i];//将所有关于发货单号对应的信息找出
							//console.log(b[i]);
						}
						
					}
				});
				$("#lv_shipment" ).select();
			}
		});
		
		$("#lv_shipment").keypress(function(e){
		  console.log($("#lv_shipment").val());
		  var key = e.which;
		  var i;
		  var j;
		  var k=0;
		  if (key == 13) { 
				var catcode="";
				var cplotno=$("#lv_shipment").val();
				$("#msg").val("");
				shipments=cplotno.split(" ");//切割铝箔袋信息
				for(var i=0;i<3;i++){
					if(shipments[i]!=""){
						catcode=catcode+shipments[i];
					}
				}
				//var catcode=shipments[0]+shipments[1]+shipments[2];//将S   M   H   AF185190D30008524011信息组合获得SMH产品参数
				var gongdanid=(shipments[3].substring(0,8));
				var gongdanid1=(shipments[3].substring(0,9));//截取shipments[3]的前9码获得工单号
				var gongdanid2=(shipments[3].substring(0,6));
				qty=(shipments[3].substring(9,13));
				
				console.log(gongdanid);
				
				$.ajax({
					type:'POST',
					url: "ph1.php",//POST傳一個超長字串到後端
					data:"Order="+Order+"&cplotno="+cplotno,//通过订单号和铝箔袋二维码获取唯一一条记录
					dataType : "JSON",
					success: function(sss){
						for(var i=0;i<a.length;i++){
							if(a[i]==sss[0].LotID){
								testlotID=1;
								$("#lv_shipment").val("存在相同的lotID").select();
							}
						}
					
						var f='';
						console.log(sss.length);
						console.log(catcode+"--"+sss[0].Catcode);
						if(sss.length==1&&testlotID==0){//如果查询有返回进行判断，如果sss.length=0说明没有查到表明信息有误
							//for(var i=0;i<b.length;i++){
								if((sss[0].ProductionNumber==gongdanid||sss[0].ProductionNumber==gongdanid1||sss[0].ProductionNumber==gongdanid2)&&sss[0].Catcode==catcode)//&&b[i].productid==sss[0].productid&&b[i].number==sss[0].number&&b[i].mdesc==sss[0].mdesc&&b[i].qty==sss[0].qty
								{
									var st = $("<td></td>").append(disksnumber+1);
									var  shipmentBin = $("<td id='"+'cbatch'+disksnumber+"'></td>").append(sss[0].ProductionNumber);
									var  shipmentLot_ID = $("<td id='"+'lotid'+disksnumber+"'></td>").append(sss[0].LotID);
									var  shipmentQty = $("<td id='"+'productid'+disksnumber+"'></td>").append(sss[0].ProductID);
									var  shipmentDate = $("<td id='"+'mdesc'+disksnumber+"'></td>").append(sss[0].ProductionNumber);
									var  shipmentKit = $("<td id='"+'number'+disksnumber+"'></td>").append(sss[0].MaterialNumber);
									var  shipmentPONum = $("<td id='"+'catcode'+disksnumber+"'></td>").append(sss[0].Catcode);
									var  qty = $("<td id='"+'qty'+disksnumber+"'></td>").append(sss[0].Qty);
									sumqty=sumqty+parseInt(sss[0].Qty);
									a[disksnumber]=sss[0].LotID;
									localStorage.name=a;
									$("#sumqty").html(sumqty);
									$("#numberss").html(disksnumber+1);
									console.log(sumqty+"--"+$("#numberss").html());
									$("<tr id='"+'shipmenttr'+disksnumber+"'></tr>")
										.append(st).append(shipmentBin).append(shipmentLot_ID).append(shipmentQty).append(shipmentDate).append(shipmentKit).append(shipmentPONum).append(qty)
										.appendTo("#dats_table tbody ").insertBefore($("#dats_table tbody tr:first"));//将td放入tr内在放入tbody然后将整行置顶
										$("#msg").val("验证通过	").css('color','green');
										disksnumber++;
										f="true";//标记验证通过
								}
							
							//}
						}
						else{
							$("#msg").val("验证失败").css('color','red');
						}
						if(f!="true"){
							$("#msg").val("验证失败").css('color','red');
						}
						testlotID=0;
					}
				});
				$("#lv_shipment").val("").select();
			}
		  });	
	
		$("#Lot_ID").keypress(function(e){    //
			  console.log($("#Lot_ID").val());
			  var i;
			  var key = e.which;
			  var testID='f';//标记匹配结果
			  if (key == 13) {
				var Lot_ID=$("#Lot_ID").val();
				for(i=0;i<disksnumber;i++){
					var Lot_IDS=document.getElementById("lotid"+i).innerHTML;//获取出库标签上的Lot_ID值
					if(Lot_ID==Lot_IDS){
						$("#shipmenttr"+i).css('color','green').insertBefore($("#dats_table tbody tr:first"));//匹配成功后出库码整行变绿并置顶
						$("#msg1").val("匹配成功").css('color','green');
						testID='t';
						$( "#Lot_ID" ).val("").select();
					}
						
				}
				 if(testID=='f'){
						$("#msg1").val("匹配失败").css('color','red');
						$("#Lot_ID" ).val("").select();
					}
				}
			});
	
		$("#btnNextbox").click(function(){//点击按钮后将table清空并清空标记符
			$( "#lv_storage" ).select();
			$("#dats_table tbody").empty();
			$("#msg").val("");
			$("#Lot_ID" ).val("");
			$("#msg1").val("");
			
			$("#lv_shipment").val("");
			$("#sumqty").html("sumqty");
			$("#numberss").html("number");
			disksnumber=0;
			sumqty=0;
		});	
	</script>
  </body>
</html>
